﻿using System.Collections.Generic;
using System.Threading;

namespace SharpObservation.Tests.Dummy
{
    public class DummyDataItem
    {
        public int Generation { get; set; }
        public int Index { get; set; }
    }


    public class DummyItemsProvider : ObservableObject, IItemsProvider<DummyDataItem>
    {
        public bool IsThreadSafe { get; set; }
        public int Generation { get; set; }
        
        #region Count Property

        /// <summary>
        /// Backing Field for Count
        /// </summary>
        private int _count;

        /// <summary>
        /// Prototype for the int property 
        /// </summary>
        private static readonly Property<DummyItemsProvider, int> CountProperty =
                  new Property<DummyItemsProvider, int>(
                      c => c.Count,
                      c => c._count,
                      (c, v) => c._count = v);

        /// <summary>
        /// Gets or Sets the int value for Count
        /// </summary>
        public int Count
        {
            get
            {
                return _count;
            }
            set { CountProperty.Set(this, value); }
        }

        #endregion



        public IEnumerable<DummyDataItem> GetRange(int startIndex, int count)
        {
            var gen = this.Generation;
            
            for (int i = startIndex; i < startIndex + count; i++)
            {
                if (IsThreadSafe)
                    Thread.Sleep(10);
                yield return new DummyDataItem { Index = i, Generation = gen };
            }
        }
    }
}
